using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NetTopologySuite.Geometries;
using ZMap.Renderer;
using ZMap.Renderer.SkiaSharp;
using ZMap.Source;

namespace ZMap.Layer
{
    public class TileLayer : Layer, ITileLayer, IComparable<TileLayer>
    {
        public string Name { get; }

        public double Opacity { get; }
        public bool Visible { get; }
        public int ZIndex { get; }
        public double MinZoom { get; }
        public double MaxZoom { get; }
        public double MaxResolution { get; }
        public double MinResolution { get; }
        public Envelope Extent { get; }
        

        public ISource Source { get; set; }

        public TileLayer()
        {
            Renderer = default(ISKTileLayerRenderer);
        }

        public int CompareTo(TileLayer other)
        {
            if (ReferenceEquals(this, other)) return 0;
            if (ReferenceEquals(null, other)) return 1;
            var nameComparison = string.Compare(Name, other.Name, StringComparison.Ordinal);
            if (nameComparison != 0) return nameComparison;
            var opacityComparison = Opacity.CompareTo(other.Opacity);
            if (opacityComparison != 0) return opacityComparison;
            var visibleComparison = Visible.CompareTo(other.Visible);
            if (visibleComparison != 0) return visibleComparison;
            var zIndexComparison = ZIndex.CompareTo(other.ZIndex);
            if (zIndexComparison != 0) return zIndexComparison;
            var minZoomComparison = MinZoom.CompareTo(other.MinZoom);
            if (minZoomComparison != 0) return minZoomComparison;
            var maxZoomComparison = MaxZoom.CompareTo(other.MaxZoom);
            if (maxZoomComparison != 0) return maxZoomComparison;
            var maxResolutionComparison = MaxResolution.CompareTo(other.MaxResolution);
            if (maxResolutionComparison != 0) return maxResolutionComparison;
            var minResolutionComparison = MinResolution.CompareTo(other.MinResolution);
            if (minResolutionComparison != 0) return minResolutionComparison;
            return Comparer<Envelope>.Default.Compare(Extent, other.Extent);
        }

        public int CompareTo(ITileLayer other)
        {
            throw new NotImplementedException();
        }
    }
}